home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / strsed.zoo / check1.c next >
C/C++ Source or Header  |  1992-07-06  |  820b  |  46 lines

  1. #include <stdio.h>
  2.  
  3. int
  4. main()
  5. {
  6.     /*
  7.      * Check simple searching.
  8.      *
  9.      * Input consists of sets of three lines containing
  10.      *
  11.      *      text
  12.      *      pattern
  13.      *      expected new text
  14.      *
  15.      * See the file examples1
  16.      *
  17.      */
  18.  
  19.     extern int strcmp();
  20.     extern char *strsed();
  21.  
  22.     char text[1024];
  23.     char pat[1024];
  24.     char ans[1024];
  25.     register char *result;
  26.     register int testno = 0;
  27.     int error = 0;
  28.  
  29.     while (gets(text) && gets(pat) && gets(ans)){
  30.         testno++;
  31.         result = strsed(text, pat, 0);
  32.         if (strcmp(ans, result)){
  33.             error = 1;
  34.             printf("WARNING (test %d)... strsed(%s, %s) returns '%s'\nExpected '%s'\n", 
  35.                 testno, text, pat, result, ans);
  36.             fflush(stdout);
  37.         }
  38.     }
  39.  
  40.     if (!error){
  41.         printf("Substitution and transliteration tests passed successfully.\n");
  42.     }
  43.  
  44.     return 0;
  45. }
  46.